//
//  TKErrorView.m
//  TopGirls
//
//  Created by Khang on 9/26/13.
//
//

#import "TKErrorView.h"

@implementation TKErrorView

- (id)init {
    if (self = [super init]) {
        imageErrorView = [[UIImageView alloc] initWithFrame:CGRectZero];
        imageErrorView.backgroundColor = [UIColor clearColor];
        [self addSubview:imageErrorView];
        
        titleView = [[UILabel alloc] initWithFrame:CGRectZero];
        titleView.backgroundColor = [UIColor clearColor];
        titleView.numberOfLines = 1;
        titleView.font = [UIFont boldSystemFontOfSize:15];
        titleView.lineBreakMode = UILineBreakModeTailTruncation;
        [self addSubview:titleView];
        
        subTitleView = [[UILabel alloc] initWithFrame:CGRectZero];
        subTitleView.backgroundColor = [UIColor clearColor];
        subTitleView.numberOfLines = 2;
        subTitleView.font = [UIFont systemFontOfSize:11];
        subTitleView.lineBreakMode = UILineBreakModeWordWrap | UILineBreakModeTailTruncation;
        [self addSubview:subTitleView];
        
        retryButton = [UIButton buttonWithType:UIButtonTypeCustom];
        retryButton.backgroundColor = [UIColor clearColor];
        [retryButton addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:retryButton];

    }
    return self;
}

- (void)dealloc {
    imageErrorView = nil;
    titleView = nil;
    subTitleView = nil;
    retryButton = nil;
}

- (void)buttonPressed:(id)sender {
    if (self.delegate && [self.delegate respondsToSelector:@selector(retryButtonPressed)]) {
        [self.delegate retryButtonPressed];
    }
}

- (void)showEmptyView:(BOOL)show {
    NSString* title = [self.delegate titleForEmptyView];
    NSString* subtitle = [self.delegate subTitleForEmptyView];
    UIImage* image = [self.delegate imageForEmptyView];
    
    [retryButton setTitle:[self.delegate titleForRetryButton] forState:UIControlStateNormal];
    
    //Do something next
}

- (void)showErrorView:(BOOL)show {
    NSString* title = [self.delegate titleForErrorView];
    NSString* subtitle = [self.delegate subTitleForErrorView];
    UIImage* image = [self.delegate imageForErrorView];
    
    [retryButton setTitle:[self.delegate titleForRetryButton] forState:UIControlStateNormal];
    
    //Do something next
}

@end
